//
//  AssetViewController.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/5/4.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class AssetViewController: BaseViewController {
    var viewModel:AssetViewModel?
    
    ///默认选中币币账户
    var selectIndex = 1
    
    lazy var assetView:AssetView = {
        let view = AssetView(dataSource: viewModel,selectIndex: selectIndex)
        return view
    }()
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        viewModel = AssetViewModel(controller: self)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.title = kText("我的资产")
        
        view.addSubview(assetView)
        assetView.snp.makeConstraints { (make) in
            make.top.left.bottom.right.equalToSuperview()
        }
        
        assetView.changeStates()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if !AppSecurityInfo.default.model.isTradePwd {
            AppSecurityInfo.default.archiveSecurityInfo()
        }
        if (viewModel?.needRefreshCoinKind)! {
        //获取支持币币交易的币种基本信息
        APPAssetInfo.default.archiveCoinInformation()
        //获取支持法币交易的币种基本信息
        APPAssetInfo.default.archiveLeverCoInformation(semaphore: nil)
        }
        viewModel?.needRefreshCoinKind = true
        viewModel?.refreshBool = true
//        viewModel?.openTimer()
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        viewModel?.closeTimer()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
